#include <stdlib.h>
#include "mylib.h"
#include "farnsworth.h"

extern const u16 farnsworth[38400];

void drawFarnsworthHead(int x, int y, int width, int height);
void blit(int dx, int dy, int sx, int sy, int swidth, int sheight);

int main(void)
{
    REG_DISPCNT = MODE3 | BG2_ENABLE;

    while (1)
    {
        waitForVblank();
        /* Draw farnsworths head*/
        /* Parameters passed in are the bounding box of his head */
        /* You are free to draw it anywhere you want */
        /* Image is contained in farnsworth defined in farnsworth.c */
        drawFarnsworthHead(29,33,60,62);
    }
}

/* x y width height are the dimensions of farnsworth's head */
/* I didn't care where you draw it but it should appear on the screen after this is called */
void drawFarnsworthHead(int x, int y, int width, int height)
{
   for (int r = 0; r < height; r++)
    {
        REG_DMA3SAD = (vu32)&farnsworth[((y+r)*(240)+(x))];
        REG_DMA3DAD = (vu32)&videoBuffer[r*240];
        REG_DMA3CNT = width | DMA_ON;
    }  
}

/* 
 Now if you can handle drawFarnsworthHead then try this one out 
 What the function drawFarnsworthHead is an example of the function below
 It is called a bitblock-transfer or blit you don't need to learn these terms for this class
 but if you want to learn more here is the wikipedia article http://en.wikipedia.org/wiki/Bit_blit
 
 So you will write this function called blit it takes six parameters
 the destination x (dx) and destination y (dy) which tells where the image will go.
 
 and the last four parameters (sx, sy, swidth, sheight) give the dimensions and location of the bounding box of the image
 
 So in summary this function is like drawFarnsworthHead except I also want to put this image on the screen at (dx, dy)
*/
void blit(int dx, int dy, int sx, int sy, int swidth, int sheight)
{
}


/* After this consider if the farnsworth image wasn't the same dimensions as the screen
How would your code change? */
